﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Web;

namespace PaymentHelper.Core.CommonUtils
{
    public class CacheStorage:ITemporaryStorage
    {
        private string _fileDependency;
        private Cache CacheRepository
        {
            get 
            {
                return HttpContext.Current.Cache;
            }
        }

        public bool CheckExist(string name)
        {
            return (CacheRepository[name] != null);
        }

        public void SaveObject(string name, object obj)
        {
            if (!CheckExist(name))
            {               
                CacheDependency cachDep = new CacheDependency(HttpContext.Current.Server.MapPath(_fileDependency));
                CacheRepository.Insert(name, obj, cachDep);
            }
        }

        public object GetObject(string name)
        {
            return CacheRepository[name];
        }

        public void setFileDependency(string fileName)
        {
            _fileDependency = fileName;
        }
    }
}
